package org.demo.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.inject.Inject;
import javax.sql.DataSource;

@Configuration
@Profile("production")
public class StandaloneDataConfiguration {

    /* ---- Instance Variables ---- */
    @Inject private Environment environment;


    /* ---- Configuration Beans ---- */

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(this.environment.getProperty("datasource.driverClassName"));
        dataSource.setUrl(this.environment.getProperty("datasource.url"));
        dataSource.setUsername(this.environment.getProperty("datasource.username"));
        dataSource.setPassword(this.environment.getProperty("datasource.password"));
        return dataSource;
    }



}
